package at.main.android;
/* 
 *  Convert J2ME to Android v.001
 *  Author: Van Tan Tai 
 *  Mail  : itvan@live.com
 *  Date  : 11.11.2010
 * 
 */
import android.view.View;

public class CanvasJ2ME {
	public static final int DOWN = 6;
	public static final int FIRE = 8 ;
	public static final int GAME_A = 9 ;
	public static final int GAME_B = 10 ;
	public static final int GAME_C = 11 ;
	public static final int GAME_D = 12 ;
	public static final int KEY_NUM0 = 48 ;
	public static final int KEY_NUM1 = 49 ;
	public static final int KEY_NUM2 = 50 ;
	public static final int KEY_NUM3 = 51 ;
	public static final int KEY_NUM4 = 52 ;
	public static final int KEY_NUM5 = 53 ;
	public static final int KEY_NUM6 = 54 ;
	public static final int KEY_NUM7 = 55 ;
	public static final int KEY_NUM8 = 56 ;
	public static final int KEY_NUM9 = 57 ;
	public static final int KEY_POUND = 35 ;
	public static final int KEY_STAR = 42 ;
	public static final int LEFT = 2 ;
	public static final int RIGHT = 5 ;
	public static final int UP = 1 ;
	
	public static final int CLEAR = -8 ;
	public static final int LEFT_SOFTKEY = -6;
	public static final int RIGHT_SOFTKEY = -7;

	public static CanvasJ2ME instance = null;
	
	public CanvasJ2ME(){
		instance = this;
	}
	
	public View getView(){
		return Static.view;
	}
	public static void initialize(View v){
		Static.view = v;
	}	
	public void setFullScreenMode(boolean enable){
		Static.windowFullScreen(Static.App);
	}
	public int getWidth(){
		return CBase.isGotWH ? Static.view.getWidth() : Implement.instance.display.getWidth();
	}
	public int getHeight(){
		return CBase.isGotWH ? Static.view.getHeight() : Implement.instance.display.getHeight();
	}
	protected int getKeyCode(int KEYDEF){
		return 0; // depend on device
	}
	protected int getGameAction(int keyCode) {
		switch(keyCode){
		case -1:
		case KEY_NUM2: return UP;
		case -2:
		case KEY_NUM8: return DOWN;
		case -3:
		case KEY_NUM4: return LEFT;
		case -4:
		case KEY_NUM6: return RIGHT;
		case -5:
		case 10:
		case 13:
		case KEY_NUM5: return FIRE;
		default: return keyCode;
		}
	}
	protected void repaint(){
		Static.view.postInvalidate();
	}
	protected void serviceRepaints(){
		// nothing
	}
	
	//public Graphics getGraphics(){ return g; }
	//boolean isDoubleBuffered() {}
	protected boolean hasRepeatEvents() { return true;}
	protected boolean hasPointerMotionEvents() { return true;}
	protected boolean hasPointerEvents() { return true;}
	//String getKeyName(int keyCode) {}
	
	// --- event
	protected void keyPressed(int keyCode) {}
	protected void keyReleased(int keyCode) {}
	protected void keyRepeated(int keyCode) {}
	
	protected void pointerDragged(int x, int y) {}
	protected void pointerPressed(int x, int y) {}
	protected void pointerReleased(int x, int y) {}
	
	protected void hideNotify() {}
	protected void showNotify() {}
	
	protected void sizeChanged(int width, int height){}
	
	protected void paint(Graphics g) {}
}
